﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.Data.SqlClient;


public partial class kecheng_search : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["sUserName"] == null)
        {

            Response.Write("<script language=javascript>alert('未登录或登录已到期，请返回登录页面重新登录！');window.close();</script>");
            Response.Write("<script language=javascript> window.open('../logout.aspx',target='_top')</script>");
            return;
        }

        Session["sTittle"] = "课程查询";
        //以下取得参数（在masterpage中定义的zxdpkey,zxdptype2)
        string zxdkey = Request.QueryString["zxdpkey"];
        string zxdtype2 = Request.QueryString["zxdptype2"];
        string zconj;
        if (zxdkey == "")
        {
            zconj = "fenlei2='" + zxdtype2 + "'";
        }
        else
        {
            zconj = "[name] like '%" + zxdkey + "%'" + " AND fenlei2='" + zxdtype2 + "'";
        }
        //取得参数完毕
        string zjigou = Session["sJigou"].ToString().Trim();
        zconj = "SELECT k.[id],k.[name],k.[xuefei],a.[username1] FROM [kecheng] k inner join [account] a on k.[laoshi]=a.[username] WHERE " + zconj + " AND [confirm]='终审通过' AND (k.[jigou]='" + zjigou + "' OR (k.[jigou]<>'" + zjigou + "' AND [fabuzt]='公开课程')) ORDER BY k.[xtsj2] DESC";
        SqlDataSource1.SelectCommand = zconj;
    }


    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        //以下，当课程已经报名或已经通过时，字体显示粉色
        //相关session变量：Session["sKecheng"]，Session["sKechenged"]
        //keydata技巧：GridView1.DataKeys[4]["laoshi"].ToString()
        if (Session["sRole"].ToString() == "学员" & e.Row.RowIndex != -1)
        {
            string zid = "," + GridView1.DataKeys[e.Row.RowIndex]["id"].ToString() + ",";
            if (Session["sKecheng"].ToString().IndexOf(zid) > 0 | Session["sKechenged"].ToString().IndexOf(zid) > 0)
            {
                e.Row.Cells[0].ForeColor = System.Drawing.Color.Red;
            }
        }
    }
    protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
    {
        if (e.NewSelectedIndex >= 0)
        {
            string zsql = "SELECT k.[id],k.[name],k.[xuefei],k.[jigou],k.[kechenglx],k.[fabuzt],k.[jifen],k.[jianjie],a.[username1] FROM [kecheng] k inner join [account] a on k.[laoshi]=a.[username] where k.[id]=" + GridView1.Rows[e.NewSelectedIndex].Cells[1].Text;
            SqlDataSource2.SelectCommand = zsql;
        }
        else
        {
            DetailsView1.Visible = false;
        }
    }


    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        //打开kecheng_play_temp.传递参数：

        //最全代码：Response.Write("<script language=javascript> window.open('../mystudy/kecheng_play.aspx','newwindow', 'height=100,width=400,top=0,left=0,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=no')</script>");
        //本节应用代码：Response.Write("<script language=javascript> window.open('../mystudy/kecheng_play.aspx','newwindow', 'height=768,width=1024,top=0,left=0,toolbar=no,resizable=yes,menubar=no,location=no,status=no')</script>");
        //string zid=GridView1.Rows[e.NewSelectedIndex].Cells[3].Text;
        //string zname = GridView1.Rows[e.NewSelectedIndex].Cells[4].Text;
        if (e.CommandName.ToString() != "Select" & e.CommandName.ToString() != "Page" & e.CommandName.ToString() != "Sort")
        {
            string zid = e.CommandArgument.ToString();
            //能成功运行的命令--Response.Write("<script language=javascript> window.open('../mystudy/kecheng_play.aspx','newwindow', 'height=768,width=1024,top=0,left=0,toolbar=no,resizable=yes,menubar=no,location=no,status=no')</script>");

            //修改后（加入参数传递）不能运行Response.Write("<script language=javascript> window.open('../mystudy/kecheng_play_temp.aspx?rid='"+zid+",'kecheng_play_window', 'height=768,width=1024,top=0,left=0,toolbar=no,resizable=yes,menubar=no,location=no,status=no')</script>");
            string zscript = "<script text='text/javascript'> window.open('../mystudy/kecheng_play_temp.aspx?rid=" + zid + "','kecheng_play_window', 'height=768,width=1024,top=0,left=0,toolbar=no,resizable=yes,menubar=no,location=no,status=no');</script>";
            Response.Write(zscript);
        }
    }
}
